/* GMGPrintOrderSurfacesManager.js <?php
#   --------------------------------------------------------------
#   GMGPrintOrderSurfacesManager.js 2011-01-24 gambio
#   Gambio GmbH
#   http://www.gambio.de
#   Copyright (c) 2011 Gambio GmbH
#   Released under the GNU General Public License (Version 2)
#   [http://www.gnu.org/licenses/gpl-2.0.html]
#   --------------------------------------------------------------
?>*/
/*<?php
if($GLOBALS['coo_debugger']->is_enabled('uncompressed_js') == false)
{
?>*/
function GMGPrintOrderSurfacesManager(p_surfaces_groups_id){this.v_surfaces=new Object();this.v_name='';this.v_current_surfaces_id=0;this.v_surfaces_groups_id=p_surfaces_groups_id;this.load_surface=function(p_name,p_width,p_height,p_surfaces_id){var coo_surface=new GMGPrintOrderSurfaces(p_surfaces_id,this);this.v_surfaces[p_surfaces_id]=coo_surface;this.v_surfaces[p_surfaces_id].set_width(p_width);this.v_surfaces[p_surfaces_id].set_height(p_height);this.v_surfaces[p_surfaces_id].set_name(p_name);this.set_current_surfaces_id(p_surfaces_id);};this.load_surfaces_group=function(p_surfaces_groups_id){var coo_surfaces_group;var coo_elements;var t_first_surfaces_id;var c_product;var c_surfaces_groups_id=gm_gprint_clear_number(p_surfaces_groups_id);jQuery.ajax({data:'action=load_surfaces_group&surfaces_groups_id='+c_surfaces_groups_id+'&XTCsid='+gm_session_id,url:'<?php echo GM_HTTP_SERVER . DIR_WS_CATALOG; ?>gm_gprint_order_ajax.php',dataType:'json',type:"POST",async:false,success:function(p_surfaces_group){coo_surfaces_group=p_surfaces_group;}});if(coo_surfaces_group.v_current_surfaces_id!='0'){this.reset_display();for(var t_surfaces_id in coo_surfaces_group.v_surfaces){if(t_first_surfaces_id==null){t_first_surfaces_id=t_surfaces_id;}this.load_surface(coo_surfaces_group.v_surfaces[t_surfaces_id].v_name,coo_surfaces_group.v_surfaces[t_surfaces_id].v_width,coo_surfaces_group.v_surfaces[t_surfaces_id].v_height,t_surfaces_id);this.display_surface(t_surfaces_id);coo_elements=coo_surfaces_group.v_surfaces[t_surfaces_id].v_elements;this.v_surfaces[t_surfaces_id].load_elements(coo_elements);}this.set_name(coo_surfaces_group.v_name);this.set_current_surfaces_id(t_first_surfaces_id);this.display_surface(t_first_surfaces_id);this.activate_tabs();}this.show();};this.activate_tabs=function(){var coo_surfaces_manager_copy=this;$('#order_surfaces_groups_id_'+this.get_surfaces_groups_id()+' .gm_gprint_tab, #order_surfaces_groups_id_'+this.get_surfaces_groups_id()+' .gm_gprint_tab_active').click(function(){var f_clicked_surfaces_id=$(this).attr('id');f_clicked_surfaces_id=f_clicked_surfaces_id.replace(/gm_gprint_tab_/g,'');c_clicked_surfaces_id=gm_gprint_clear_number(f_clicked_surfaces_id);coo_surfaces_manager_copy.set_current_surfaces_id(c_clicked_surfaces_id);coo_surfaces_manager_copy.display_surface(coo_surfaces_manager_copy.get_current_surfaces_id());});};this.display_surface=function(p_surfaces_id){$('#order_surfaces_groups_id_'+this.get_surfaces_groups_id()+' .gm_gprint_tab_active').each(function(){$(this).removeClass('gm_gprint_tab_active');$(this).addClass('gm_gprint_tab');});$('#gm_gprint_content_'+this.get_surfaces_groups_id()+' .gm_gprint_surface').each(function(){$(this).hide();});if($('#tab_'+p_surfaces_id).attr('id')!='tab_'+p_surfaces_id){$('#gm_gprint_tabs_'+this.get_surfaces_groups_id()).append('<li class="gm_gprint_tab_active" id="tab_'+this.v_surfaces[p_surfaces_id].get_surfaces_id()+'"><span>'+this.v_surfaces[p_surfaces_id].get_name()+'</span></li>');$('#gm_gprint_content_'+this.get_surfaces_groups_id()).append('<div class="gm_gprint_surface" id="surface_'+this.v_surfaces[p_surfaces_id].get_surfaces_id()+'" style="overflow: hidden; position: relative; width: '+this.v_surfaces[p_surfaces_id].get_width()+'px; height: '+this.v_surfaces[p_surfaces_id].get_height()+'px;"></div>');}else{$('#tab_'+p_surfaces_id).removeClass('gm_gprint_tab');$('#tab_'+p_surfaces_id+' span').html(this.v_surfaces[p_surfaces_id].get_name());$('#tab_'+p_surfaces_id).addClass('gm_gprint_tab_active');$('#surface_'+p_surfaces_id).show();}$('#gm_gprint_tabs_'+this.get_surfaces_groups_id()+' .gm_gprint_tab').mouseover(function(){$(this).css({'text-decoration':'underline'});});$('#gm_gprint_tabs_'+this.get_surfaces_groups_id()+' .gm_gprint_tab_active').mouseover(function(){$(this).css({'text-decoration':'none'});});$('#gm_gprint_tabs_'+this.get_surfaces_groups_id()+' .gm_gprint_tab').mouseout(function(){$(this).css({'text-decoration':'none'});});};this.reset_display=function(){$('#gm_gprint_tabs_'+this.get_surfaces_groups_id()).html('');$('#gm_gprint_content_'+this.get_surfaces_groups_id()).html('');};this.show=function(){$('#gm_gprint_tabs_'+this.get_surfaces_groups_id()).show();$('#gm_gprint_content_'+this.get_surfaces_groups_id()).show();};this.update_current_surfaces_id=function(p_surfaces_id){var c_surfaces_id=gm_gprint_clear_number(p_surfaces_id);var t_success=jQuery.ajax({data:'action=set_current_order_surfaces_id&surfaces_id='+c_surfaces_id+'&XTCsid='+gm_session_id,url:'<?php echo GM_HTTP_SERVER . DIR_WS_CATALOG; ?>gm_gprint_order_ajax.php',type:"POST",async:true}).responseText;};this.set_name=function(p_name){this.v_name=gm_unescape(p_name);};this.get_name=function(){return this.v_name;};this.set_current_surfaces_id=function(p_surfaces_id){this.v_current_surfaces_id=p_surfaces_id;};this.get_current_surfaces_id=function(){return this.v_current_surfaces_id;};this.set_surfaces_groups_id=function(p_surfaces_groups_id){this.v_surfaces_groups_id=v_surfaces_groups_id;};this.get_surfaces_groups_id=function(){return this.v_surfaces_groups_id;};}
/*<?php
}
else
{
?>*/
function GMGPrintOrderSurfacesManager(p_surfaces_groups_id)
{
    this.v_surfaces = new Object();
    this.v_name = '';
    this.v_current_surfaces_id = 0;
    this.v_surfaces_groups_id = p_surfaces_groups_id;

    this.load_surface = function(p_name, p_width, p_height, p_surfaces_id)
	{
		var coo_surface = new GMGPrintOrderSurfaces(p_surfaces_id, this);

        this.v_surfaces[p_surfaces_id] = coo_surface;
        this.v_surfaces[p_surfaces_id].set_width(p_width);
        this.v_surfaces[p_surfaces_id].set_height(p_height);
        this.v_surfaces[p_surfaces_id].set_name(p_name);

        this.set_current_surfaces_id(p_surfaces_id);
	}

    this.load_surfaces_group = function(p_surfaces_groups_id)
	{
        var coo_surfaces_group;
		var coo_elements;
		var t_first_surfaces_id;
		var c_product;
		var c_surfaces_groups_id = gm_gprint_clear_number(p_surfaces_groups_id);

		jQuery.ajax({
            data: 'action=load_surfaces_group&surfaces_groups_id=' + c_surfaces_groups_id + '&XTCsid=' + gm_session_id,
            url: '<?php echo GM_HTTP_SERVER . DIR_WS_CATALOG; ?>gm_gprint_order_ajax.php',
            dataType: 'json',
            type: "POST",
            async: false,
            success: function(p_surfaces_group)
			{
				coo_surfaces_group = p_surfaces_group;
			}
        });

		if(coo_surfaces_group.v_current_surfaces_id != '0')
		{
			this.reset_display();

			for(var t_surfaces_id in coo_surfaces_group.v_surfaces)
			{
				if(t_first_surfaces_id == null)
				{
					t_first_surfaces_id = t_surfaces_id;
				}

				this.load_surface(coo_surfaces_group.v_surfaces[t_surfaces_id].v_name, coo_surfaces_group.v_surfaces[t_surfaces_id].v_width, coo_surfaces_group.v_surfaces[t_surfaces_id].v_height, t_surfaces_id);
				this.display_surface(t_surfaces_id);

				coo_elements = coo_surfaces_group.v_surfaces[t_surfaces_id].v_elements;
				this.v_surfaces[t_surfaces_id].load_elements(coo_elements);
			}

			this.set_name(coo_surfaces_group.v_name);
			this.set_current_surfaces_id(t_first_surfaces_id);
			this.display_surface(t_first_surfaces_id);

			this.activate_tabs();
		}

		this.show();
    }

	this.activate_tabs = function()
	{

		var coo_surfaces_manager_copy = this;

		$('#order_surfaces_groups_id_' + this.get_surfaces_groups_id() + ' .gm_gprint_tab, #order_surfaces_groups_id_' + this.get_surfaces_groups_id() + ' .gm_gprint_tab_active').click(function()
		{
			var f_clicked_surfaces_id = $(this).attr('id');
            f_clicked_surfaces_id = f_clicked_surfaces_id.replace(/gm_gprint_tab_/g, '');

            c_clicked_surfaces_id = gm_gprint_clear_number(f_clicked_surfaces_id);

            coo_surfaces_manager_copy.set_current_surfaces_id(c_clicked_surfaces_id);
            coo_surfaces_manager_copy.display_surface(coo_surfaces_manager_copy.get_current_surfaces_id());
        });
    }

    this.display_surface = function(p_surfaces_id)
	{
        $('#order_surfaces_groups_id_' + this.get_surfaces_groups_id() + ' .gm_gprint_tab_active').each(function()
		{
            $(this).removeClass('gm_gprint_tab_active');
            $(this).addClass('gm_gprint_tab');
        });

        $('#gm_gprint_content_' + this.get_surfaces_groups_id() + ' .gm_gprint_surface').each(function()
		{
            $(this).hide();
        });

        if($('#tab_' + p_surfaces_id).attr('id') != 'tab_' + p_surfaces_id)
		{
            $('#gm_gprint_tabs_' + this.get_surfaces_groups_id()).append('<li class="gm_gprint_tab_active" id="tab_' + this.v_surfaces[p_surfaces_id].get_surfaces_id() + '"><span>' + this.v_surfaces[p_surfaces_id].get_name() + '</span></li>');
            $('#gm_gprint_content_' + this.get_surfaces_groups_id()).append('<div class="gm_gprint_surface" id="surface_' + this.v_surfaces[p_surfaces_id].get_surfaces_id() + '" style="overflow: hidden; position: relative; width: ' + this.v_surfaces[p_surfaces_id].get_width() + 'px; height: ' + this.v_surfaces[p_surfaces_id].get_height() + 'px;"></div>');
        }
        else
		{
            $('#tab_' + p_surfaces_id).removeClass('gm_gprint_tab');
			$('#tab_' + p_surfaces_id + ' span').html(this.v_surfaces[p_surfaces_id].get_name());
			$('#tab_' + p_surfaces_id).addClass('gm_gprint_tab_active');
			$('#surface_' + p_surfaces_id).show();
        }

		$('#gm_gprint_tabs_' + this.get_surfaces_groups_id() + ' .gm_gprint_tab').mouseover(function()
		{
			$(this).css({
				'text-decoration': 'underline'
			});
		});

		$('#gm_gprint_tabs_' + this.get_surfaces_groups_id() + ' .gm_gprint_tab_active').mouseover(function()
		{
			$(this).css({
				'text-decoration': 'none'
			});
		});

		$('#gm_gprint_tabs_' + this.get_surfaces_groups_id() + ' .gm_gprint_tab').mouseout(function()
		{
			$(this).css({
				'text-decoration': 'none'
			});
		});
    }

	this.reset_display = function()
	{
		$('#gm_gprint_tabs_' + this.get_surfaces_groups_id()).html('');
		$('#gm_gprint_content_' + this.get_surfaces_groups_id()).html('');
	}

	this.show = function()
	{
		$('#gm_gprint_tabs_' + this.get_surfaces_groups_id()).show();
		$('#gm_gprint_content_' + this.get_surfaces_groups_id()).show();
	}

	this.update_current_surfaces_id = function(p_surfaces_id)
	{
        var c_surfaces_id = gm_gprint_clear_number(p_surfaces_id);

		var t_success = jQuery.ajax({
            data: 'action=set_current_order_surfaces_id&surfaces_id=' + c_surfaces_id + '&XTCsid=' + gm_session_id,
            url: '<?php echo GM_HTTP_SERVER . DIR_WS_CATALOG; ?>gm_gprint_order_ajax.php',
            type: "POST",
            async: true
        }).responseText;
    }

	this.set_name = function(p_name)
	{
		this.v_name = gm_unescape(p_name);
	}

	this.get_name = function()
	{
		return this.v_name;
	}

    this.set_current_surfaces_id = function(p_surfaces_id)
	{
        this.v_current_surfaces_id = p_surfaces_id;
    }

    this.get_current_surfaces_id = function()
	{
        return this.v_current_surfaces_id;
    }

    this.set_surfaces_groups_id = function(p_surfaces_groups_id)
	{
        this.v_surfaces_groups_id = v_surfaces_groups_id;
    }

    this.get_surfaces_groups_id = function()
	{
        return this.v_surfaces_groups_id;
    }
}
/*<?php
}
?>*/

